package cn.net.autocode.platform.config;

import cn.net.autocode.dbManager.Dao;
import cn.net.autocode.dbManager.DbManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

@Configuration
public class DaoConfig {


    @Bean
    @Primary
    public Dao dataDao(@Autowired DataSource dataSource) {
        return new DbManager(dataSource);
    }

    @Bean
    public Dao dictDao(@Qualifier("dictDataSource") DataSource dataSource) {
        return new DbManager(dataSource);
    }

    @Bean
    @Primary
    public DataSourceTransactionManager dataTxManager(@Autowired DataSource dataSource){
        DataSourceTransactionManager txManager = new DataSourceTransactionManager();
        txManager.setDataSource(dataSource);
        return txManager;
    }

    @Bean
    public DataSourceTransactionManager dictTxManager(@Qualifier("dictDataSource") DataSource dataSource){
        DataSourceTransactionManager txManager = new DataSourceTransactionManager();
        txManager.setDataSource(dataSource);
        return txManager;
    }
}

